package main

import (
	"fmt"
	"time"
)

// Timer只执行一次，Ticker可以周期的执行。
// func main() {
// 	ticker := time.NewTicker(time.Second)
// 	counter := 1
// 	for _ = range ticker.C {
// 		fmt.Println("ticker 1")
// 		counter++
// 		if counter >= 5 {
// 			break
// 		}
// 	}
// 	ticker.Stop()
// }

func main() {
	chanInt := make(chan int)
	ticker := time.NewTicker(time.Second)
	go func() {
		for _ = range ticker.C {
			select {
			case chanInt <- 1:
			case chanInt <- 2:
			case chanInt <- 3:
			}
		}
	}()

	sum := 0
	for v := range chanInt {
		fmt.Printf("接受： %v\n", v)
		sum += v
		if sum >= 10 {
			fmt.Printf("sum: %v\n", sum)
			break
		}
	}
}
